using Godot;

public partial class SaveSlotUI : Control
{
    // UI 引用
    [Export] public Label NameLabel;
    [Export] public Label TimeLabel;
    [Export] public Button PlayButton;
    [Export] public Button DeleteButton;

    private SaveData _data;
    private MainMenu _menuRef; // 引用主菜单以便回调

    public void Setup(SaveData data, MainMenu menu)
    {
        _data = data;
        _menuRef = menu;

        NameLabel.Text = data.DisplayName;
        TimeLabel.Text = "上次游玩: " + data.LastPlayedTime;
    }

    public override void _Ready()
    {
        PlayButton.Pressed += OnPlayPressed;
        DeleteButton.Pressed += OnDeletePressed;
    }

    private void OnPlayPressed()
    {
        // 通知全局管理器加载此存档
        GameManager.Instance.LoadSave(_data);
    }

    private void OnDeletePressed()
    {
        // 简单确认可以加在这里，为了演示直接删除
        SaveSystem.DeleteSave(_data.FileName);
        // 通知主菜单刷新列表
        _menuRef.RefreshSaveList();
    }
}